﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using BLL;

namespace WebUI.SystemManage
{
    public partial class UsersEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            bn_close.OnClientClick = ActiveWindow.GetConfirmHideReference();
            if(!IsPostBack)
            {
                SwichPanel();
            }
        }

        private void SwichPanel()
        {
            string aciton = Request.QueryString["action"];
            if(aciton == "new")
            {
                PageManager1.AutoSizePanelID = "newPanel";
                newPanel.Hidden = false;
            }
        }

        protected void bnNew_OnClick(object sender, EventArgs e)
        {
            Model.Users u = new Model.Users();
            u.username = tb_username.Text.Trim();
            u.pwd = Common.Md5.getMd5(tb_pwd.Text.Trim());
            u.name = tb_name.Text;
            u.sid = tb_sid.Text;
            u.isTeacher = ck_isTeacher.Checked;
            if(UsersManage.Add(u) > 0)
            {
                PageContext.RegisterStartupScript(Alert.GetShowInTopReference("新增用户成功！", "操作提示！", MessageBoxIcon.Information) + ActiveWindow.GetHidePostBackReference(Common.LinkService.RefreshString));
            }
            else
            {
                Alert.Show("新增用户遇到错误！", "失败", ExtAspNet.MessageBoxIcon.Error);
            }
        }
    }
}